package com.iwhalecloud.uncc.utils;

import com.iwhalecloud.uncc.common.ArchiverConstant;
import com.iwhalecloud.uncc.dao.ArchiverDao;
import com.iwhalecloud.uncc.model.ArchiverModel;
import com.iwhalecloud.uncc.model.InsEventRecord;

import java.time.Instant;
import java.util.Date;
import java.util.List;

/**
 * @author zq
 * @date 2021/10/31 9:58
 * @description
 */
public class CheckUtil {

    public static List batchQuery(ArchiverDao archiverDao, List list) {
        if(list != null && !list.isEmpty()){
            return archiverDao.batchQuery(list);
        }
        return null;
    }

    public static void batchInsert(ArchiverDao archiverDao, List list, String newPartitionCode) {
        if(list != null && !list.isEmpty()){
            for (Object o : list) {
                ArchiverModel a= (ArchiverModel)o;
                a.setPartitionCode(newPartitionCode);
                a.setArchiverTime(Date.from(Instant.now()));
            }
            archiverDao.batchInsert(list);
        }
    }

    public static void batchUpdateArchiving(ArchiverDao archiverDao, List list) {
        if(list != null && !list.isEmpty()){
            archiverDao.batchUpdate(ArchiverConstant.ARCHIVING,list);
        }
    }

    public static void batchUpdateArchived(ArchiverDao archiverDao, List list) {
        if(list != null && !list.isEmpty()){
            archiverDao.batchUpdate(ArchiverConstant.ARCHIVED,list);
        }
    }

    public static void batchResetOnline(ArchiverDao archiverDao, List list) {
        if(list != null && !list.isEmpty()){
            archiverDao.batchUpdate(ArchiverConstant.ONLINE,list);
        }
    }

    public static void batchDelete(ArchiverDao archiverDao, List list) {
        if(list != null && !list.isEmpty()){
            archiverDao.batchDelete(list);
        }
    }

    public static List<InsEventRecord> dealInsEventRecord(List<InsEventRecord> insEventRecordList, List<InsEventRecord> l) {
        if(insEventRecordList == null && l != null){
            insEventRecordList = l;
        }
        if(insEventRecordList != null && l != null){
            insEventRecordList.addAll(l);
        }
        return insEventRecordList;
    }
}
